package com.hysh.framework.aspectj;

import com.hysh.system.domain.FaceVefLog;
import com.hysh.common.core.domain.FaceResult;
import com.hysh.system.service.FaceVefLogService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Aspect
public class FaceAspect {

    @Autowired
    private FaceVefLogService faceVefLogService;

    @AfterReturning(value = "@annotation(com.hysh.common.annotation.FaceLog)",returning = "res")
    public void addLog(JoinPoint joinPoint , Object res){
        FaceResult result = (FaceResult)res;
        FaceVefLog faceVefLog = new FaceVefLog();
        faceVefLog.setVefTime(new Date());
        faceVefLog.setVefCode(result.getCode());
        faceVefLog.setVefMsg(result.getMsg());
        faceVefLog.setLoginName(result.getName());
        faceVefLogService.save(faceVefLog);
    }

}
